package com.atguigu.lease.web.admin.custom.config;

import com.atguigu.lease.web.admin.custom.converter.StringToBaseEnumConverter;
import com.atguigu.lease.web.admin.custom.interceptor.AuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * ClassName  WebMvcConfiguration
 * Author  XiaojianOne
 * Date  2025/2/24 22:28
 * Version  8.0
 */

@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Autowired
    private AuthenticationInterceptor authenticationInterceptor;

    @Autowired
    private StringToBaseEnumConverter stringToBaseEnumConverter;

    /**
     * 注册ConverterFactory  实现枚举类型转换
     * @param registry
     */
    @Override
    public void addFormatters(FormatterRegistry registry) {

        registry.addConverterFactory(stringToBaseEnumConverter);
    }


    /**
     * 注册拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(this.authenticationInterceptor).
                addPathPatterns("/admin/**").
                excludePathPatterns("/admin/login/**");
    }
}
